package com.fava.quiz;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;

public class Utility {
	
	public static CharSequence readTextFile(Context context, String fileName) {
        BufferedReader in = null;
        try {
                in = new BufferedReader(new InputStreamReader(context.getAssets().open(fileName)));
                String line;
                StringBuilder buffer = new StringBuilder();
                while ((line = in.readLine()) != null) buffer.append(line).append('\n');
                return buffer;
        } catch (IOException e) {
                System.out.println(e.getMessage());
                return "";
        } finally {
                if (in != null) {
                        try {
                                in.close();
                        } catch (IOException e) {
                                // Ignore
                        }
                }
        }
	}
	
	public static void removeButtons(Button b) {
		ViewGroup layout = (ViewGroup) b.getParent();
		if (layout != null) {
			layout.removeView(b);
		}
	}
	
	
	public static void animation (View v, int screenWidth, int sceltaAnim) {
		Animation animation;
		int  x=screenWidth;
		x-=v.getWidth()+v.getLeft();
			switch (sceltaAnim){
			
			case 1:
				animation= new RotateAnimation(0, 1800,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
				animation.setDuration(350);
				animation.setFillAfter(false);
				v.startAnimation(animation);
				break;
		}
	}
	
			
			
}
